/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/selection.h"
#include "PlanetWars2dRT-core/specific/model/player_playing_functions.h"


EXTERN_C_BEGIN


ship_t**
selection_2d_uint_get_ships(universe_t* a_universe,
			    const selection_2d_uint* a_selection,
			    size_t* nb)
{
  /* TODO */
  if(a_universe == NULL || a_selection == NULL || nb == NULL)
    {
      if(nb != NULL)
	{
	  *nb = 0;
	}
      return NULL;
    }
  *nb = 0;
  return NULL;
}

/**
 * @param[out] nb Number of ships
 */
ship_t**
selection_2d_uint_get_ships_of_player_index(universe_t* a_universe,
					    const selection_2d_uint* a_selection,
					    unsigned char player_index,
					    size_t* nb)
{
  if(a_universe == NULL || a_selection == NULL || nb == NULL)
    {
      if(nb != NULL)
	{
	  *nb = 0;
	}
      return NULL;
    }
  if(a_selection->type == SELECTION_2D_TYPE_RECTANGLE)
    {
      struct position_2d_uint position;
      position.x = RECTANGLE_GET_TOP_LEFT_POSITION_X(a_selection->zone.rectangle);
      position.y = RECTANGLE_GET_TOP_LEFT_POSITION_Y(a_selection->zone.rectangle);
      struct size_2d_uint size;
      size.x = RECTANGLE_GET_WIDTH (a_selection->zone.rectangle);
      size.y = RECTANGLE_GET_HEIGHT(a_selection->zone.rectangle);
      vector_ship_ptr ships =
	universe_get_vector_ships_of_player_index_in_rectangle(a_universe,
							       player_index,
							       &position,
							       &size);
      *nb  = VECTOR_GENERIC_STATIC_GET_SIZE_UNSAFE(&ships);
      return VECTOR_GENERIC_STATIC_GET_DATA_UNSAFE(&ships);
    }
  
  *nb = 0;
  return NULL;
}


EXTERN_C_END
